<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小西瓜 <751707632@qq.com.com>
// +----------------------------------------------------------------------
namespace app\api\model;

use app\admin\model\RouteModel;
use think\Model;               
use tree\Tree;
use think\Db;
use app\api\model\ImsJoinLogModel;

class ImsMeetingJoinModel extends Model
{

    /**
     * 根据ID查询我的会议列表
     * @param arry $where 查询条件
     * @param [int] $[page] [<分页>]
     * @param [int] $[limit] [<显示条数>]
     * @param string $order 查询顺序
     * @return array
     */
    public function myMeetingList($where=array(), $page=1, $limit=5, $order='vm.id desc, vm.status asc')
    {
        $list = $this->alias('mj')
        ->join('__IMS_MEETING_LIVE__ vm','vm.id = mj.vm_id', 'left')
        ->join('__IMS_MEMBER__ im','im.id = vm.user_id', 'left')
        ->join('__PORTAL_CATEGORY__ pc','vm.type_id = pc.id', 'left')
        ->field('mj.is_must,pc.name,vm.vm_title,vm.compere_id,vm.cover_pic,vm.compere_name,vm.start_time,vm.duration,vm.status,im.staff_name,im.staff_duty,im.staff_deptname')
        ->where($where)->order($order)->page($page, $limit)->select()->toArray();
        foreach ( $list as $key => $val ) {
            $list[$key]['cover_pic'] = cmf_get_image_url(str_replace("\\","/",$val['cover_pic'])); // 处理图片
            $list[$key]['status_name'] = meetingStatus()[$val['status']];
            $list[$key]['ctegory_name'] = $val['name'];
            unset($list[$key]['name']);

            // 查询参会记录
            $joinLogModel = new  ImsJoinLogModel();
            $joinInfo = $joinLogModel->joinLogShow(['vm_id'=>$val['id'], 'is_vm'=>2], $val['start_time'], $val['duration']);
            $list[$key]['join_info'] = $joinInfo;
            $list[$key]['join_status'] = $joinInfo['join_status'];
        }

        $count = $this->alias('mj')
        ->join('__IMS_MEETING_LIVE__ vm','vm.id = mj.vm_id', 'left')
        ->join('__IMS_MEMBER__ im','im.id = vm.compere_id', 'left')
        ->join('__PORTAL_CATEGORY__ pc','vm.type_id = pc.id', 'left')
        ->where($where)->count();

        return ['list'=>$list, 'count'=>$count];
        // return $where;
    }
}